package com.cookman.utils;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.cookman.actions.*;
import com.cookman.assets.*;
import com.cookman.cards.CityCard;
import com.cookman.world.entities.Disease;
import com.cookman.world.entities.Player;
import com.cookman.world.entities.Roles;

/**
 * Created by Cookman on 19.09.14.
 */
public class AssetUtils {

    public static Sprite getActionSprite(Action action) {
        if (action instanceof MovePlayerByCarAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BYCAR);
        } else if (action instanceof MovePlayerByLabAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BYLAB);
        } else if (action instanceof MovePlayerByLabAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BYLAB);
        } else if (action instanceof MovePlayerCharterFlightAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.CHARTER);
        } else if (action instanceof MovePlayerDirectFlightAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.FLIGHT);
        } else if (action instanceof BuildLabAsEngineerAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BUILDLABENGINEER);
        } else if (action instanceof BuildLabAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BUILDLAB);
        } else if (action instanceof SkipMoveAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.ENDTURN);
        } else if (action instanceof CureInfectionAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.CUREACTION);
        } else if (action instanceof InventCureAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.INVENTCURE);
        } else if (action instanceof CardsExchangeAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.CARDEXCHANGE);
        } else if (action instanceof MovePlayerAsEngineerAction) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BYLABENGINEER);
        }
        return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.ACTIONS, AssetActions.BYCAR);
    }

    public static Sprite getActiveCityAssetsByColor(String color) {
        if (color.equals(Disease.RED)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_RED);
        } else if (color.equals(Disease.BLACK)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_BLACK);
        } else if (color.equals(Disease.YELLOW)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_YELLOW);
        } else if (color.equals(Disease.BLUE)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_BLUE);
        }
        return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_RED);
    }

    public static Sprite getInactiveCityAssetsByColor(String color) {
        if (color.equals(Disease.RED)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_RED_INACTIVE);
        } else if (color.equals(Disease.BLACK)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_BLACK_INACTIVE);
        } else if (color.equals(Disease.YELLOW)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_YELLOW_INACTIVE);
        } else if (color.equals(Disease.BLUE)) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_BLUE_INACTIVE);
        }
        return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.CITY_RED_INACTIVE);
    }

    public static Sprite getPlayerSprite(Player player) {
        if (player.getRole().name().equals(Roles.ENGINEER.name())) {
            return new Sprite(AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.ENGINEER));
        } else if (player.getRole().name().equals(Roles.MEDIC.name())) {
            return new Sprite(AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.MEDIC));
        } else if (player.getRole().name().equals(Roles.DISPATCHER.name())) {
            return new Sprite(AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.DISPATCHER));
        } else if (player.getRole().name().equals(Roles.EXPERT.name())) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.EXPERT);
        } else if (player.getRole().name().equals(Roles.QUARANTINE.name())) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.QUARANTINE);
        } else if (player.getRole().name().equals(Roles.SCIENTIST.name())) {
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.SCIENTIST);
        }

        return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.ENGINEER);
    }

    public static Sprite getCityCardSprite(CityCard card) {
        if (AssetsLocator.hasSprite(AssetsImpl.CITY_CARD, card.getCity().getId())) {
            return new Sprite(AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY_CARD, card.getCity().getId()));
        } else {
            //   Gdx.app.debug("CityCard asset not found. Return default one: ","");
            return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY_CARD, AssetCityCard.BOHOTA);
        }
    }

    public static Sprite getDiseaseByColor(String color) {
        switch (color) {
            case Disease.BLACK:
                return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.DISEASE_BLACK);
            case Disease.BLUE:
                return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.DISEASE_BLUE);
            case Disease.YELLOW:
                return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.DISEASE_YELLOW);
            case Disease.RED:
                return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.DISEASE_RED);
        }
        return AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.CITY, AssetCity.DISEASE_BLACK);
    }
}
